﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SSS.handler
{
    /// <summary>
    /// InventoryHandler 的摘要说明
    /// </summary>
    public class InventoryHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            // 取消浏览器缓存
            Common.Tools.SetPageNoCache();
            // 设置返回类型
            //context.Response.ContentType = "text/plain";
            context.Response.ContentType = "application/json";
            context.Response.Charset = "utf-8";

            #region 请求响应
            switch (context.Request["cmd"].ToLower())
            {
                case "purchase_add":               // 入库登记
                    context.Response.Write(purchaseAdd(context.Request["data"]));
                    break;
                default:
                    break;
            }
            #endregion
        }

        private string purchaseAdd(string jsonStr)
        {
            // 从jsonStr中解析Purchase对象
            //AddPurchase( string ID, string Pwd, string IP, Purchase purchase )
            // 
            if (string.IsNullOrEmpty(jsonStr))
            {
                return "{\"cmd\":\"purchase_add\",\"state\":\"失败\"}";
            }

            string str = "{\"cmd\":\"purchase_add\",\"state\":\"失败\"}";
            string cmd;
            string state;
            int i = str.IndexOf("\"cmd\":");
            if(i>0) 


            return "{\"cmd\":\"purchase_add\",\"state\":\"失败\"}";
            return "{\"cmd\":\"purchase_add\",\"state\":\"成功\",\"data\":\"1\"}";
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}